package com.hdaccp.ch05

import org.apache.spark.SparkConf
import org.apache.spark.streaming.flume.FlumeUtils
import org.apache.spark.streaming.{Seconds, StreamingContext}

object Demo2 {
  def main(args: Array[String]): Unit = {
    //1.
    val sparkConf = new SparkConf().setMaster("local[2]").setAppName("ch05Demo2App")
    //2.
    val ssc = new StreamingContext(sparkConf,Seconds(5))
    //3.
    val flumeStream = FlumeUtils.createStream(ssc,"0.0.0.0",41414)

    flumeStream.map(x=> new String(x.event.getBody.array()).trim)
      .flatMap(_.split(" ")).map((_,1)).reduceByKey(_+_).print()

    ssc.start()
    ssc.awaitTermination()
  }
}
